package com.portal.framework.dao;

import java.lang.reflect.Field;

import com.portal.framework.dao.annotation.SearchProp;
import com.portal.framework.util.StringUtils;


public class SearchPropWrapper {
	private SearchProp searchProp;
	private Field field;

	public SearchPropWrapper(Field field) {
		if (field == null) {
			throw new IllegalArgumentException("field must not null!");
		}

		this.field = field;
		this.searchProp = field.getAnnotation(SearchProp.class);
	}

	public SearchProp getSearchProp() {
		return searchProp;
	}

	public boolean isSearchProp() {
		return searchProp != null;
	}

	public String getPropName() {
		if (searchProp != null) {
			if (StringUtils.notEmptyTrimed(searchProp.fieldName())) {
				return searchProp.fieldName();
			} else {
				return field.getName();
			}
		}
		return field.getName();
	}
}
